import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: HomeView,
    children: [
      {
        path: '/',
        component: () => import('../views/product/IndexView.vue'),
        meta:{
          title: "首页"
        }
      },
      {
        path: '/category',
        component: () => import('../views/product/CategoryView.vue'),
        meta:{
          title: "查找分类"
        }
      },
      {
        path: '/search',
        component: () => import('../views/product/SearchView.vue'),
        meta:{
          title: "搜索"
        }
      },
      {
        path: '/cart',
        component: () => import('../views/product/CartView.vue'),
        meta:{
          title: "购物车"
        }
      },
      {
        path: '/clear',
        component: () => import('../views/product/ClearView.vue'),
        meta:{
          title: "结算页面"
        }
      },
      {
        path: '/detail',
        component: () => import('../views/product/DetailView.vue'),
        meta:{
          title: "商品详情页面"
        }
      },

    ]
  },
  {
    path: '/login',
    component: () => import('../views/LoginView.vue'),
    meta:{
      title: "登录页面"
    },
    children: [
      {
        path: '/login',
        component:() => import('../views/login/LoginFromView.vue'),
      }
    ]
  },
  {
    path: '/myAddress',
    component: () => import('../views/address/ShippingAddressView.vue'),
    meta:{
      title: "我的收货地址"
    }
  },
  {
    path: '/address/add',
    component: () => import('../views/address/AddNewAddressView.vue'),
    meta:{
      title: "添加收货地址"
    }
  },
  {
    path: '/address/change',
    component: () => import('../views/address/ChangeAddressView.vue'),
    meta:{
      title: "修改收货地址"
    }
  },
  {
    path: '/userinfo',
    component: () => import('../views/user/InfoView.vue'),
    meta:{
      title: "个人信息"
    }
  },
  {
    path: '/userChange',
    component: () => import('../views/user/ChangeInfoView.vue'),
    meta:{
      title: "修改个人信息"
    }
  },
  {
    path: '/reg',
    component: () => import('../views/RegView.vue'),
    meta:{
      title: "注册页面"
    },
    children: [
      {
        path: '/reg',
        component:() => import('../views/reg/FirstRegView.vue'),
      }
    ]
  },
  {/*后台管理*/
    path: '/admin',
    component: () => import('../views/AdminView.vue'),
    children:[
      {
        path: '/admin/bookList',
        component: () => import('../views/admin/BookListView.vue'),
        meta: {
          title: "所有图书"
        }
      },{
        path: '/admin/bookAdd',
        component: () => import('../views/admin/BookAddView.vue'),
        meta: {
          title: "上架图书"
        }
      },{
        path: '/admin/category',
        component: () => import('../views/admin/CategoryView.vue'),
        meta: {
          title: "分类管理"
        }
      },
      {
        path: '/admin/banner',
        component: () => import('../views/admin/BannerListView.vue'),
        meta: {
          title: "轮播图列表"
        }
      },
      {
        path: '/admin/addBanner',
        component: () => import('../views/admin/AddBannerView.vue'),
        meta: {
          title: "添加轮播图"
        }
      },
      {
        path: '/admin/userList',
        component: () => import('../views/admin/UserListView.vue'),
        meta: {
          title: "用户管理"
        }
      },{
        path: '/admin/adminAdd',
        component: () => import('../views/admin/AdminAddView.vue'),
        meta: {
          title: "添加管理员"
        }
      },{
        path: '/admin/adminList',
        component: () => import('../views/admin/AdminListView.vue'),
        meta: {
          title: "管理员列表"
        }
      },{
        path: '/admin/test',
        component: () => import('../views/admin/TestView'),
        meta: {
          title: "测试页面"
        }
      }
      ]}
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  if (to.meta.title){
    document.title = to.meta.title
  }
  next()
})


export default router
